﻿Imports System.Text
Public Class Form1

    Private upfile As New upfile

    Private Function host_info(ByVal Path As String) As String
        Dim value As String = ""
        Dim a As String = ""
        Dim MySF As IO.StreamReader = New IO.StreamReader(Path, System.Text.Encoding.Default)
        value = MySF.ReadToEnd() '讀取全部會包含換行符號 
        MySF.Close()
        Return value
    End Function

    Private Function Regular(ByVal InputSTR As String, ByVal RegularSTR As String) As RegularExpressions.MatchCollection
        Try
            Dim reg As New System.Text.RegularExpressions.Regex(RegularSTR)
            Return reg.Matches(InputSTR)
        Catch ex As Exception
            Return Nothing
        End Try
    End Function


    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Shell(upfile.exe_path, vbNormalFocus)
        Me.Close()
    End Sub



    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim hostInfo As String = host_info(System.Environment.CurrentDirectory + "\host_info.txt")
        Try
            LinkLabel1.Text = Regular(hostInfo, "title=([^;]+);").Item(0).Groups(1).ToString
            upfile.TimeOut = Int(Regular(hostInfo, "timeout=([^;]+);").Item(0).Groups(1).ToString)
            upfile.exe_path = Regular(hostInfo, "exe_path=([^;]+);").Item(0).Groups(1).ToString
            upfile.modules_path = Regular(hostInfo, "modules_path=([^;]+);").Item(0).Groups(1).ToString
            upfile.URL = Regular(hostInfo, "updata_url=([^;]+);").Item(0).Groups(1).ToString
            upfile.host_link = Regular(hostInfo, "host_link=([^;]+);").Item(0).Groups(1).ToString
            upfile.upldownload_api = Regular(hostInfo, "upldownload_api=([^;]+);").Item(0).Groups(1).ToString
            If upfile.host_link <> "0" Then

                LinkLabel1.Links.Add(0, Len(upfile.host_link), upfile.host_link)

            End If

            upfile.Start()
        Catch ex As Exception
            MsgBox("host_info.txt文件損壞", MsgBoxStyle.Critical, "訊息")
        End Try
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        upfile.Download()

    End Sub

    Private Sub Form1_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown

        Me.Hide()

    End Sub

    Private Sub LinkLabel1_LinkClicked(ByVal sender As Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
        Try
            System.Diagnostics.Process.Start(upfile.host_link)
        Catch ex As Exception
            MsgBox("維護社群網址不正確", MsgBoxStyle.Critical, "訊息")
        End Try

    End Sub

    Private Sub Panel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint

    End Sub
End Class
